package com.topboya.linker.ui.activity;

import android.content.Intent;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.topboya.linker.R;
import com.topboya.linker.model.levelitem.SelectDeviceGroup;
import com.topboya.linker.model.levelitem.SelectVistorItem;
import com.topboya.linker.model.response.CustomerByIdResponse;
import com.topboya.linker.model.response.DictByKeyResponse;
import com.topboya.linker.model.response.TitleDictResopnse;
import com.topboya.linker.ui.base.activity.BaseActivity;
import com.topboya.linker.ui.presenter.SeeSpecificPresenter;
import com.topboya.linker.ui.view.SeeSpecificView;
import com.topboya.linker.utils.LogUtils;

import java.util.ArrayList;
import java.util.List;

public class SeeSpecificActivity extends BaseActivity<SeeSpecificView,SeeSpecificPresenter> implements SeeSpecificView {
    private static final String TAG = "SeeSpecificActivity";

    private Toolbar toolbar;
    private TextView toolbar_title;
    private TextView tv_toolbar_right;
    private TextView tv_see_name;
    private TextView tv_select_dapartment;
    private TextView tv_select_professional;
    private TextView tv_phone;
    private TextView tv_see_address;
    private Button btn_save;
    private SelectVistorItem selectVistorItem;
    private String id;
    private List<DictByKeyResponse.Data> listDepartment;
    private List<TitleDictResopnse.Data> listTitle;
    private CustomerByIdResponse.Data data;
    private SelectDeviceGroup docDetailInfo;

    @Override
    protected int getLayoutId() {

        return R.layout.activity_seespecific_customer;
    }

    @Override
    protected void initView() {

        toolbar = findViewById(R.id.toolbar);
        toolbar_title = findViewById(R.id.toolbar_title);
        tv_toolbar_right = findViewById(R.id.tv_toolbar_right);
        tv_see_name = findViewById(R.id.tv_see_name);
        tv_select_dapartment = findViewById(R.id.tv_select_dapartment);
        tv_select_professional = findViewById(R.id.tv_select_professional);
        tv_phone = findViewById(R.id.tv_phone);
        tv_see_address = findViewById(R.id.tv_see_address);
        btn_save = findViewById(R.id.btn_save);
        toolbar_title.setText("查看客户");
        tv_toolbar_right.setVisibility(View.GONE);

    }

    @Override
    protected void initData() {

        listDepartment = new ArrayList<>();
        listTitle = new ArrayList<>();
        selectVistorItem = (SelectVistorItem) getIntent().getSerializableExtra("selectVistorItem");
        docDetailInfo = (SelectDeviceGroup) getIntent().getSerializableExtra("docDetailInfo");
        id = selectVistorItem.getId();
        mPresenter.getDictByKey("hos_department");
    }

    @Override
    protected void initListener() {

        toolbar.setNavigationOnClickListener(v -> { finish(); });
        btn_save.setOnClickListener(v -> {

            Intent intent = new Intent(SeeSpecificActivity.this,EditCustomerActivity.class);
            intent.putExtra("data",data);
            intent.putExtra("docDetailInfo",docDetailInfo);

            startActivity(intent);

        });

    }

    @Override
    protected SeeSpecificPresenter createPresenter() {

        return new SeeSpecificPresenter(this);
    }

    @Override
    public void getCustomerById(CustomerByIdResponse.Data data) {

        LogUtils.v(TAG + "DATA:"+data);
        this.data = data;
        tv_see_name.setText(data.getCusName());
        for (int i=0;i <listDepartment.size();i++){
            if (listDepartment.get(i).getValue().equals(data.getDepartment())){

                tv_select_dapartment.setText(listDepartment.get(i).getLabel());
                this.data.setDepartmetlabel(listDepartment.get(i).getLabel());

                break;
            }
        }
       for (int i=0;i <listTitle.size();i++){

           if (listTitle.get(i).getValue().equals(data.getPosit())){

               tv_select_professional.setText(listTitle.get(i).getLabel());
               this.data.setPositlabel(listTitle.get(i).getLabel());

               break;
           }
       }
        tv_phone.setText(data.getPhone());

    }

    @Override
    public void setPickViewData(List<DictByKeyResponse.Data> listDepartment, List<TitleDictResopnse.Data> listTitle) {

        this.listDepartment.clear();
        this.listTitle.clear();
        this.listDepartment.addAll(listDepartment);
        this.listTitle.addAll(listTitle);
        mPresenter.getCustomerById(id);

    }
}
